package com.qx.grainmall.cart.vo;

import lombok.Data;

import java.math.BigDecimal;
import java.util.List;

@Data
public class CartVo {

    //所有商品列表
    private List<CartItemVo> items;

    /**
     * 商品数量
     */
    private Integer countNum;

    /**
     * 商品类型数量
     */
    private Integer countType;

    /**
     * 商品总价
     */
    private BigDecimal totalAmount;

    /**
     * 减免价格
     */
    private BigDecimal reduce = new BigDecimal("0.00");;

    public List<CartItemVo> getItems() {
        return items;
    }

    public void setItems(List<CartItemVo> items) {
        this.items = items;
    }
    //商品数量 统计
    public Integer getCountNum() {
        countNum = 0;
        for (CartItemVo item : items) {
            countNum += item.getCount();
        }
        return countNum;
    }

    //商品类型数量
    public Integer getCountType() {
        countType = 0;
        for (CartItemVo item : items) {
            countType += 1;
        }
        return countType;
    }

    //总价格 计算总价格
    public BigDecimal getTotalAmount() {
        BigDecimal ta = new BigDecimal("0.0");
        if(items!=null && items.size()>0){
            for (CartItemVo item : items) {
                ta = ta.add(item.getTotalPrice());
            }
        }
        //计算减免价格
        return ta.subtract(this.reduce);
    }


    public BigDecimal getReduce() {
        return reduce;
    }

    public void setReduce(BigDecimal reduce) {
        this.reduce = reduce;
    }
}
